<?php

class Users_Form_Userprofileupdate extends Zend_Form {

    public function init() {
        $validation = new Validations_User();
        $db = new Users_Model_Users();
        $result = $db->getUser($validation->getUserId());


        //creating form
        $this->setAction('/users/profile/update')
                ->setMethod('post');

        //getting values...
        $contact1 = '';
        $contact2 = '';
        $adds = '';
        $name = $result[0]['name'];
        if ($result[0]['contact_number'] != null) {
            $djson = json_decode($result[0]['contact_number']);
            $contact1 = $djson->contact->primary_contact;
            $contact2 = $djson->contact->secondary_contact;
            $adds = $result[0]['address'];
        }

        //full name
        $fullName = new Zend_Form_Element_Text('name');
        $fullName->setLabel('Name:')
                ->setOptions(array('placeholder' => 'Enter your full-name.'))
                ->setRequired(true)
                ->setValue($name)
                ->addFilter('stringTrim');

        $primaryContact = new Zend_Form_Element_Text('primary_contact');
        $primaryContact->setLabel('Primary Contact Number')
                ->setOptions(array('placeholder' => 'Contact Number'))
                ->setRequired(true)
                ->setValue($contact1)
                ->addValidator('regex', false, array('/^[0-9 ]+$/'))
                ->addErrorMessage("Invalid telephone number");

        $secondaryContact = new Zend_Form_Element_Text('sec_contact');
        $secondaryContact->setLabel('Secondary Contact Number')
                ->setOptions(array('placeholder' => 'Contact Number'))
                ->setValue($contact2)
                ->addValidator('regex', false, array('/^[0-9 ]+$/'))
                ->addErrorMessage("Invalid telephone number");

        $address = new Zend_Form_Element_Textarea('address');
        $address->setLabel('Address')
                ->setOptions(array('placeholder' => 'Your Home Address', 'cols' => '40', 'rows' => '4'))
                ->setValue($adds)
                ->setRequired(true);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Update Profile')
                ->setOptions(array('class' => 'submit'))
                ->setAttrib('class', 'btn btn-success');


        $this->addElements(array($fullName, $primaryContact, $secondaryContact, $address, $submit));
    }

}